#coding: utf-8
class Shared::Department < ActiveRecord::Base
  has_many :provinces, :class_name => 'Shared::Province', :foreign_key => 'department'
  has_many :complaints, :class_name => 'RequestAndComplaint::Complaint', :foreign_key => 'department'
  has_many :cultural_institutions, :class_name => 'CulturalHeritage::CulturalInstitution', :foreign_key => 'department'
  default_scope where("deleted = 0")

  def erasable
    compla = RequestAndComplaint::Complaint.count_department_dependencies(id)
    cultu_insti = CulturalHeritage::CulturalInstitution.count_department_dependencies(id)
    inci = CulturalHeritage::Incidence.count_department_dependencies(id)
    provi = Shared::Province.count_department_dependencies(id)
    reg_req = RequestAndComplaint::RegistrationRequest.count_department_dependencies(id)
    if compla >0
      return "Imposible borrar. Existen dependencias en denuncia"    
    end
    if cultu_insti >0
      return "Imposible borrar. Existen dependencias en institucion cultural"    
    end
    if inci >0
      return "Imposible borrar. Existen dependencias en incidencia"    
    end
    if provi >0
      return "Imposible borrar. Existen dependencias en provincia"    
    end
    if reg_req >0
      return "Imposible borrar. Existen dependencias en registro de solicitud"    
    end
    return nil
  end
end
